package org.springframework.data.repository.query;

import java.util.Locale;

import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;

public class QueryLookupStrategy {

	public static enum Key {

		CREATE, USE_DECLARED_QUERY, CREATE_IF_NOT_FOUND;

		/**
		 * Returns a strategy key from the given XML value.
		 *
		 * @param xml
		 * @return a strategy key from the given XML value
		 */
		@Nullable
		public static Key create(String xml) {

			if (!StringUtils.hasText(xml)) {
				return null;
			}

			return valueOf(xml.toUpperCase(Locale.US).replace("-", "_"));
		}
	}

}
